<template>
  <u-swiper v-if="computedBannerList.length > 0" :list="computedBannerList" :height="height" :title="true" @click="go"></u-swiper>
</template>

<script>
/**
 * 注意该组件依赖 uview-ui 库
 */
import BannerUrl from '../../../../pc/BannerUrl.js'
export default {
  name: "st-banner",
  props: {
    height: {
      default: 350
    },
    groupFlag: {
      type: String
    }
  },
  computed: {
    computedBannerList(){
      let r = []
      this.bannerList.forEach(item => {
        r.push({
          image: item.imgUrl,
          title: item.imgDescription
        })
      })
      return r
    }
  },
  data(){
    return {
      bannerList: []
    }
  },
  mounted(){
    this.loadAvailableBannerList()
  },
  methods:{
    // 加载 banner 数据
    loadAvailableBannerList(){
      this.$http.get(BannerUrl.getAvailableList,{params: {groupFlag: this.groupFlag}}).then(res =>{
        this.bannerList = res.data
      })
    },
    // 点击 banner 图片跳转到对应页面
    go(index){
      let url = this.bannerList[index].actionLink
      if(!url){
        return
      }
      uni.navigateTo({
        url: url
      })
    }
  }
}
</script>

<style scoped>

</style>